/**
 * create by ck on 2016/3/21.
 */
var ids;
var inList;
var outList;
var inListParams;
var outListParams;
$(document).ready(function(){
    var classId  = xhTool.getQuery('iSCLId');
    var schoolId = xhTool.getQuery('iSchoolId');
    var DataGrid2 = new DataGridEvent();
    inList = $('#InList');
    outList = $('#OutList');
    inListParams = {"iSCLId": classId};
    outListParams = {"iSCLId": classId, "iSchoolId": schoolId};
    $('.xh-datagrid-toolbar').parseToolbar(afterParseToolbar);
    $('iframe:last', window.parent.document).height($('.panel-body:first', window.parent.document).height());
    inList.initDataGrid('getStudentInClassDgData', {"queryParams": inListParams})
        .setSelectThenEnable(['bt_out'], [], 'bs');
    outList.initDataGrid('getStudentOutClassDgData', {"queryParams": outListParams}, DataGrid2)
        .setSelectThenEnable(['bt_in'], [], 'bs', DataGrid2);
    $('#bt_in').click(function(){
        ids = outList.getDataGridSelectedFields('iUserId');
        $.post(baseUrl + 'Class/addStudentInClass', {ids:ids, iSCLId:classId}, function(){
            $('#bt_in, #bt_out').setButtonDisable('bs');
            inList.dataGridReload();
            outList.dataGridReload();
        });
    });
    $('#bt_out').click(function(){
        ids = inList.getDataGridSelectedFields('iUserId');
        $.post(baseUrl + 'Class/delStudentInClass', {ids: ids, iSCLId: classId}, function(){
            $('#bt_in, #bt_out').setButtonDisable('bs');
            inList.dataGridReload();
            outList.dataGridReload();
        });
    });
});

function afterParseToolbar()
{
    $('#bt_OutList_Search').click(function(){
        var _search = {
            "vague" : $('#OutList_Search').getElementValue(),
            "items" : $('#OutList_Search_Item').getElementValue(true)
        };
        outListParams = $.extend({}, outListParams, {"search": _search});
        outList.addDataGridParams(outListParams);
    });
    $('#OutList_Search').textbox('textbox').on('keydown', function(event) {
        if(event.keyCode == 13) {
            $('#bt_OutList_Search').click();
        }
    });
    $.overtFun.vagueSearch(inList, inListParams, $('#InList_Search'), $('#bt_InList_Search'));
    //$.overtFun.vagueSearch(outList, outListParams, $('#OutList_Search'), $('#bt_OutList_Search'));

}